package com.shop.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.Sms_Coupon_Mapper;
import com.shop.service.Sms_Coupon_Service;
import com.shop.pojo.sms.Sms_Coupon;
import com.shop.utils.LayuiUtils;
import com.shop.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class Sms_Coupon_ServiceImpl implements Sms_Coupon_Service
{

    @Autowired
    private Sms_Coupon_Mapper sms_coupon_mapper;


    /**
     * 后台查询所有优惠卷信息显示
     * @param page
     * @param sms_coupon
     * @return
     */
    @Override
    public LayuiUtils<Sms_Coupon> find_admin_coupon_All(Page<Sms_Coupon> page, Sms_Coupon sms_coupon) {
        LayuiUtils<Sms_Coupon> layuis = new LayuiUtils<>();
        QueryWrapper<Sms_Coupon> Query = new QueryWrapper<>();
        if(sms_coupon.getCoupon_name() != null){
            Query.like("coupon_name",sms_coupon.getCoupon_name());
        }

        Page<Sms_Coupon> sms_couponPage = sms_coupon_mapper.selectPage(page,Query);
        layuis.setCount(sms_couponPage.getTotal());
        layuis.setData(sms_couponPage.getRecords());
        return layuis;
    }




    /**
     * 后台优惠卷新增的方法
     * @param sms_coupon
     * @return
     */
    @Override
    public R insert_admin_coupon_All(Sms_Coupon sms_coupon){

        Sms_Coupon s = new Sms_Coupon();
        int insert = sms_coupon_mapper.insert(sms_coupon);
        if(insert>0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    @Override
    public R delete_admin_coupon_All(List<Integer> id) {
        int i = sms_coupon_mapper.deleteBatchIds(id);
        if(i > 0){
            return R.success();
        }
        return R.error(500,"删除失败");
    }

    @Override
    public R up_admin_coupon_All(Sms_Coupon sms_coupon) {
        int i = sms_coupon_mapper.updateById(sms_coupon);
        if(i > 0){
            return R.success();
        }
        return R.error(500,"修改失败");
    }


}
